#ifndef _TEST_H_
#define _TEST_H_

#include <QList>
#include <QMetaType>
#include <QObject>
#include <QQmlContext>
#include <QQuickView>
#include <QTime>
#include <memory>
#include <unistd.h>


#include "inputmethodlistmodel.h"


class TestQml {
public:
  TestQml() {
    initModel();
    initView();
  }
  ~TestQml() {}

  void show_window() {
    if (view_.get() == nullptr) {
      return;
    }

    view_->show();
  }

private:
  void initModel() {
    provider_.reset(new FcitxDbusProvider());

    model_.reset(new InputMethodListModel(provider_.get(), nullptr));
  }

  void initView() {
    view_.reset(new QQuickView());
    view_->setTitle("qml demo");

    view_->rootContext()->setContextProperty("inputMethodModel", model_.get());

    view_->setColor(QColor(Qt::transparent));
    view_->setSource(QUrl("../test.qml"));
  }

private:
  std::unique_ptr<QQuickView> view_ = nullptr;
  std::unique_ptr<FcitxDbusProvider> provider_ = nullptr;

  std::unique_ptr<InputMethodListModel> model_ = nullptr;
};

#endif
